<template>
  <div class="h-full flex flex-col overflow-auto">
    <a-card>
      <a-form ref="formRef" :model="formState" class="flex justify-between form-style-flex">
        <div class="flex">
          <a-form-item name="brName" class="w-[260px] mr-3 !mb-0">
            <SelectTable
              v-model:value="formState.brName"
              :search-params="{ stdate: formState.stdate, eddate: formState.eddate, type: '2' }"
              type="门诊挂号患者列表"
              placeholder="姓名/助记码/卡号/手机号/身份证号"
              @select="onSelect"
            />
          </a-form-item>
          <a-form-item label="挂号时间" class="!mb-0">
            <div class="flex">
              <a-date-picker v-model:value="formState.stdate" placeholder="开始时间" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
              <a-date-picker v-model:value="formState.eddate" class="ml-2" placeholder="结束时间" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
            </div>
          </a-form-item>
        </div>
        <div>
          <a-button style="margin: 0 8px" @click="onClickReset">重置</a-button>
          <a-button type="primary" @click="onClickRefresh">刷新</a-button>
        </div>
      </a-form>
    </a-card>
    <PatientInfoHeader :patient-info="tableData" :show-insurance="false" class="mt-2" @change="onClickReset">
      <a-divider type="vertical" :style="{ height: '40px', margin: '0 16px' }" />
      <div>
        <div class="flex items-center">
          <LabelValue label="卡号" :value="tableData.brId" :width="160" label-class="w-[52px] text-right" />
          <LabelValue label="病案号" :value="tableData[isBGMSG ? 'brBlkh' : 'oprSn']" :width="160" />
          <LabelValue label="科室" :value="tableData.ksmc" :width="160" />
          <LabelValue label="类别" :value="tableData.ghlb" :width="160" />
        </div>
        <div class="flex items-center">
          <LabelValue label="门诊号" :value="tableData.jzbh" :width="160" />
          <LabelValue label="病历号" :value="tableData[isBGMSG ? 'oprSn' : 'brBlkh']" :width="160" />
          <LabelValue label="医生" :value="tableData.empName" :width="160" />
          <LabelValue label="时间" :value="tableData.ghsj" :width="200" />
        </div>
      </div>
    </PatientInfoHeader>
    <div class="mt-2 flex flex-1 overflow-hidden">
      <div class="w-3/5 mr-2 relative overflow-auto">
        <a-card>
          <div class="flex justify-between items-center mb-2">
            <div class="flex items-center">
              <BaseTitle title="收费明细" class="mt-2">
                <div class="ml-4 flex items-center">
                  <span class="font-normal pr-2">处置</span>
                  <a-switch v-model:checked="czFlag" :disabled="!jzbh" @change="onClickRefresh()" />
                  <span class="font-normal pr-2 ml-2">处方</span>
                  <a-switch v-model:checked="cfFlag" :disabled="!jzbh" @change="onChangeCfSwitch" />
                  <a-select
                    v-if="cfFlag"
                    v-model:value="cfbhList"
                    :max-tag-count="3"
                    :disabled="!jzbh"
                    mode="multiple"
                    placeholder="请选择"
                    :options="cfbhData"
                    allow-clear
                    class="ml-2 w-[260px]"
                    @change="onClickRefresh()"
                  />
                </div>
              </BaseTitle>
            </div>
            <div class="flex">
              <span class="font-normal pr-2 mt-1">显示套餐</span>
              <a-switch v-model:checked="packageSwitch" :disabled="!tableDataDetail.length" class="mt-1" @change="onClickRefresh" />
              <a-button type="primary" class="ml-2" :disabled="!tableDataDetail.length" @click="onClickDiscounts(1)"> 批量打折 </a-button>
            </div>
          </div>
          <!--tableDataDetail中 orderType  2:套餐明细  不可取消勾选 -->
          <BaseTable
            :loading="loading"
            column-code="00001108"
            :scroll="{ x: 1000 }"
            :height="getLeftTableHeight()"
            :data-source="tableDataDetail"
            row-key="id"
            bordered
            :row-selection="{
              selectedRowKeys: tableDetailId,
              onChange: onSelectChange,
              getCheckboxProps: (record) => ({
                disabled: record.orderType === '2'
              })
            }"
          >
            <template #bodyCell="{ column, index, record }">
              <template v-if="column.dataIndex === 'xh'">
                {{ index + 1 }}
              </template>
              <template v-if="column.dataIndex === 'xmmc'">
                <template v-if="record.orderType === '1'">
                  <PopoverTable :width="800" :config="detailConfig" :params="{ jzbh, orderType: [2], tcid: record.tcid, cfbh: record.cfbh, yzzt: 1, jfzt: 0 }">
                    <template #bodyCell="{ column: popColumn, record: popRecord }">
                      <template v-if="popColumn.dataIndex === 'xmmc'">
                        <MedicineInfo :value="{ mc: popRecord.xmmc, gg: popRecord.gg, cj: popRecord.cj }">
                          <template #suffix>
                            <a-badge v-if="popRecord?.insureFlag !== 1" count="自" class="ml-2" :number-style="{ backgroundColor: '#ff9540' }" />
                          </template>
                        </MedicineInfo>
                      </template>
                    </template>
                    {{ record?.xmmc }}
                  </PopoverTable>
                </template>
                <template v-else>
                  <MedicineInfo :value="{ mc: record?.xmmc, gg: record?.gg, cj: record?.cj }">
                    <template #suffix>
                      <a-badge v-if="record?.insureFlag === 0" count="自" class="ml-2" :number-style="{ backgroundColor: '#ff9540' }" />
                    </template>
                  </MedicineInfo>
                </template>
              </template>
              <template v-if="column.dataIndex === 'yzzt'">
                <a-tag v-if="!+record.yzzt" color="green">正常</a-tag>
                <a-tag v-else color="red">失效</a-tag>
              </template>
              <template v-if="column.dataIndex === 'action'">
                <a-button type="link" size="small" @click="onClickDiscounts(record)"> 打折 </a-button>
              </template>
            </template>
          </BaseTable>
        </a-card>
        <div class="absolute w-full">
          <div v-if="showPrescription" class="overflow-auto overflow-x-hidden" style="max-height: 340px">
            <a-card v-for="(item, index) in prescriptionList" :key="index" class="mt-2 pb-4">
              <div class="flex mb-2">
                <BaseTitle class="!w-[150px] !mb-0" :title="'中药处方' + (index + 1) + '-加工'" />
                <div class="flex items-center">
                  <a-select v-model:value="item.drugStoreId" class="w-64" placeholder="请选择" :options="drugRoomList" />
                  <a-radio-group v-model:value="item.jzfs" class="ml-5" @change="onChangeRadio(item)">
                    <a-radio value="自煎">自煎</a-radio>
                    <a-radio value="代煎">代煎</a-radio>
                  </a-radio-group>
                </div>
              </div>
              <div class="w-full">
                <div class="flex mb-2">
                  <div class="font-bold mx-2">加工</div>
                  <div class="flex-1 cursor-pointer border-b-style min-w-80" @click="onClickProcessOpen(item)">
                    <a-input :value="generateProcess(item.processMethod)" readonly :bordered="false" class="w-full pt-0" placeholder="请选择加工方式" />
                  </div>
                  <div class="font-bold mx-2">加工费：￥{{ formatAmount(item.processMethod.processMethodCost) }}</div>
                  <BaseButton type="text" confirm-text="确认删除?" danger size="small" @click="onDelCost(item, 'JGF')">删除</BaseButton>
                </div>
                <div class="flex">
                  <div class="font-bold mx-2">快递</div>
                  <div class="flex-1 cursor-pointer border-b-style min-w-80" @click="onClickexpressOpen(item)">
                    <a-input :value="generateExpress(item.express)" readonly :bordered="false" class="w-full pt-0" placeholder="请输入快递信息" />
                  </div>
                  <div class="font-bold mx-2">快递费：￥{{ formatAmount(item.express.expressCost) }}</div>
                  <BaseButton v-if="item.express?.expressMode" confirm-text="确认删除?" type="text" danger size="small" @click="onDelCost(item, 'KD')">
                    删除
                  </BaseButton>
                </div>
              </div>
            </a-card>
          </div>
        </div>
      </div>

      <div class="w-2/5 flex flex-col overflow-auto">
        <a-card class="w-full">
          <BaseTitle title="收费类别" class="!mb-2.5" />
          <BaseTable :loading="loading" column-code="00001107" :data-source="tableDataType" bordered :height="getRightTableHeight()">
            <template #bodyCell="{ column, index }">
              <template v-if="column.dataIndex === 'xh'">
                {{ index + 1 }}
              </template>
            </template>
            <!-- <template #footer>
              <div class="text-right w-full px-4">
                <template v-if="isCharge">
                  <span v-if="tableData.chargeStandardName"> ({{ tableData.chargeStandardName }})</span>
                </template>
                医疗费：<span class="text-xl font-bold text-red-500">￥{{ formatAmount(medicalPrice) }}</span>
              </div>
            </template> -->
          </BaseTable>
        </a-card>
        <div class="flex flex-col relative w-full flex-1">
          <!-- <CouponCard v-if="isCoupon" ref="couponRef" v-model:value="tableData.brId" :medical-price="categoryPrice" class="mt-2" @success="onSuccessCoupon" />
          <a-card class="mt-2">
            <BaseTitle title="分币误差" class="!mb-0">
              <span>
                分币：<span class="text-red-500 font-bold">￥{{ formatAmount(differenceAmount) }}</span>
              </span>
            </BaseTitle>
          </a-card>
          <a-card class="mt-2">
            <div class="flex justify-between items-center">
              <div class="flex">
                <BaseTitle title="押金支付" class="!mb-0 !w-[90px]" />
                <SelectTable
                  v-if="isDeposit"
                  v-model:value="deposit"
                  class="w-[285px]"
                  :disabled="!tableData.brId"
                  :search-params="{ brId: tableData.brId, status: '0', settlementType: '1' }"
                  type="押金"
                  placeholder="请选择"
                  @select="onBlurDepositPrice"
                />
                <a-input v-else v-model:value="deposit" :disabled="!tableData.brId" class="w-[285px]" placeholder="请输入单号" @blur="onBlurDepositPrice" />
              </div>
              <div class="font-bold">
                押金：<span class="text-red-500 font-bold">￥{{ formatAmount(depositPrice) }}</span>
              </div>
            </div>
          </a-card> -->
          <a-card class="mt-2 w-full flex-1 border-t" :body-style="{ height: '100%', position: 'relative' }">
            <div class="text-right mr-2 mb-2 absolute bottom-0 right-0">
              <div class="my-2 font-bold text-lg">
                本次应收 <span class="text-xl text-red-500 font-bold">￥{{ formatAmount(medicalPrice) }}</span>
              </div>
              <a-button class="ml-2 w-28" size="large" @click="onClickReset">重置</a-button>
              <a-button type="primary" class="ml-2 w-28" size="large" :disabled="!formState.brName" @click="onSuccessPreferential"> 收费 </a-button>
            </div>
          </a-card>
        </div>
      </div>
    </div>
    <ChargeModal v-model:open="chargeOpen" :is-dispose="true" :br-id="tableData.brId" :business-data="{ ysje: medicalPrice }" @success="onSuccessPrice" />
    <ModalExpress v-model:open="expressOpen" :row-data="orderData.express" :br-id="formState.brId" @ok="onProcessOk" />
    <ModalProcess v-model:open="processOpen" :row-data="orderData.processMethod" @ok="onProcessOk" />
    <DiscountsOne v-model:open="discountsOneOpen" :row-data="projectRow" @success="onDiscountsSuccess" />
    <DiscountsMany v-model:open="discountsManyOpen" :discount-percent="discountPercent" :discounts-data="tableDataDetail" @success="onDiscountsSuccess" />
    <!-- <a-modal v-model:open="testModel" title="test msg">
      <p>{{ testModelInfo }}</p>
    </a-modal> -->
  </div>
</template>

<script setup>
import { ref, watch, onMounted } from 'vue'
import dayjs from 'dayjs'
import { message } from 'ant-design-vue'
import BaseTitle from '@/components/BaseTitle'
import SelectTable from '@/components/SelectTable'
import { formatAmount } from '@/utils/format.js'
import { post } from '@/utils/request'
import BaseTable from '@/components/BaseTable'
import ModalExpress from '@/components/ModalExpress'
import ModalProcess from '@/components/ModalProcess'
import { getSystemConfig } from '@/utils/systemConfig'
import ChargeModal from '@/components/ChargeModal'
// import PreferentialCard from '../components/PreferentialCard'
// import CouponCard from '@/components/CouponCard'
import DiscountsOne from './components/DiscountsOne'
import DiscountsMany from './components/DiscountsMany'

// const { empId } = useUserStore()
const loading = ref(false)
const chargeOpen = ref(false)
const showPrescription = ref(false)
const processOpen = ref(false)
const expressOpen = ref(false)
const discountsOneOpen = ref(false)
const discountsManyOpen = ref(false)
const isCoupon = ref(true)
const isCharge = ref(true)
const isDeposit = ref(false)
const packageSwitch = ref(false)
const czFlag = ref(true)
const cfFlag = ref(true)
const cfbhData = ref([])
const cfbhList = ref([])
const couponRef = ref(null)
const tableDataType = ref([])
const tableDataDetail = ref([])
const tableData = ref({})
const tableDetailId = ref([])
const drugRoomList = ref([])
const prescriptionList = ref([])
const projectRow = ref({})
const orderData = ref({})
const formState = ref({
  stdate: dayjs().format('YYYY-MM-DD'),
  eddate: dayjs().format('YYYY-MM-DD'),
  kh: ''
})
const jzbh = ref('')
// const categoryPrice = ref(0) // 实收金额
const formRef = ref(null)
const differenceAmount = ref(0)
const medicalPrice = ref(0) // 应收金额
const deposit = ref('')
const depositPrice = ref(0) // 押金金额
const discountPercent = ref(0)
const couponId = ref(null) // 抵用券id
const couponPrice = ref('') // 抵用券金额
const memberId = ref('') // 会员id
const memberPrice = ref('') // 会员卡钱

const getLeftTableHeight = () => {
  const topHeight = 382
  if (prescriptionList.value.length === 0) {
    return window.innerHeight - topHeight + 75
  }
  if (prescriptionList.value.length === 1 && showPrescription.value) {
    return window.innerHeight - topHeight - 90
  }
  if (prescriptionList.value.length > 1 && showPrescription.value) {
    return window.innerHeight - topHeight - 308
  }
}
const getRightTableHeight = () => {
  // const topHeight = '370'
  // const tableHeight = window.innerHeight - topHeight - 580
  // return tableHeight < 240 ? 240 : tableHeight
  // const topHeight = '70'
  const tableHeight = window.innerHeight - 480
  return tableHeight < 240 ? 240 : tableHeight
}
const onSelect = async (select) => {
  formState.value.brName = select.brName
  // tableData.value = select
  jzbh.value = select.jzbh
  deposit.value = ''
  couponId.value = ''
  memberId.value = ''
  memberPrice.value = ''
  couponPrice.value = ''
  await getOutpInfo()
}

// 获取患者信息
const getOutpInfo = async () => {
  const { code, data, msg } = await post('/outp/mzys/getOutpRecordInfo', { mzjlbh: jzbh.value })
  if (code !== 0) return message.error(msg || '获取病历信息失败')
  tableData.value = data
}

// 单项
const onClickDiscounts = async (row) => {
  // const res = await post('/operation/opex/getDiscountPermisson', { empId })
  // if (res.code !== 0) return message.error(res.msg)
  // discountPercent.value = res.data.discountPercent
  if (row === 1) {
    discountsManyOpen.value = true
  } else {
    // projectRow.value = { ...row, empZkl: discountPercent.value }
    projectRow.value = { ...row }
    discountsOneOpen.value = true
  }
}
const detailConfig = ref({
  url: '/outp/oupCharge/getOutpClinicalOrderInfoList',
  columnCode: '00001190',
  rowKey: 'id',
  formatResult: (data) => {
    return data.map((item, index) => ({
      ...item,
      NO: index + 1
    }))
  }
})
const onChangeCfSwitch = async (e) => {
  if (!e) {
    cfbhData.value = []
    cfbhList.value = []
  } else {
    await getCfData()
  }
  await chargeDetailList()
  getFeeCategoryList()
  getAmount()
}
const getFeeCategoryList = async () => {
  const { code, data, msg } = await post('/outp/oupCharge/getOutpClinicalOrderTypeList', { jzbh: jzbh.value, yzzt: 1, ids: tableDetailId.value })
  if (code !== 0) return message.error(msg)
  tableDataType.value = data
}
const getCfData = async () => {
  const { code, data, msg } = await post('/outp/oupCharge/getOutpClinicalCfbhInfoList', {
    jzbh: jzbh.value,
    orderType: packageSwitch.value ? [0, 1] : [0, 2],
    yzzt: 1,
    jfzt: 0,
    jfztList: ['0', '3']
  })
  if (code !== 0) return message.error(msg)
  if (data && data.length > 0) {
    cfbhData.value = data.map((item) => {
      return { label: item.cfmc, value: item.cfbh }
    })
    cfbhList.value = data.map((item) => {
      return item.cfbh
    })
  } else {
    cfbhData.value = []
  }
}

const chargeDetailList = async () => {
  const {
    code,
    data = [],
    msg
  } = await post('/outp/oupCharge/getOutpClinicalOrderInfoList', {
    jzbh: jzbh.value,
    orderType: packageSwitch.value ? [0, 1] : [0, 2],
    yzzt: 1,
    jfzt: 0,
    czFlag: czFlag.value ? 1 : 0,
    cfFlag: cfFlag.value ? 1 : 0,
    cfbhList: cfbhList.value
  })
  if (code !== 0) return message.error(msg)
  tableDataDetail.value = data
  tableDetailId.value = data.map((item) => item.id)
  getReceiptsCount()
}

const getReceiptsCount = async () => {
  showPrescription.value = tableDataDetail.value.some((item) => item.lbmc === '中药费')
  await getPrescription()
}

const getPrescription = async () => {
  const res = await post('/outp/outpClinicalOrder/getOutpTCMHeadList', { jzbh: [jzbh.value], jksy: 1 })
  if (res.code !== 0) return message.error(res.msg)
  prescriptionList.value = res.data
  // getReceiptsAmount()
}
const onSelectChange = (selectedRowKeys) => {
  tableDetailId.value = selectedRowKeys
  getFeeCategoryList()
  getAmount()
}
const getAmount = async () => {
  const { code, data, msg } = await post('/outp/oupCharge/getOutpClinicalOrderInfoTotalCost', { jzbh: jzbh.value, ids: tableDetailId.value })
  if (code !== 0) return message.error(msg)
  medicalPrice.value = data
  // getReceiptsAmount()
}
const getDrugRooms = async () => {
  const res = await post('/operation/opex/getDrugStoreInfoList', { status: 1 })
  if (res.code !== 0) return message.error(res.msg)
  drugRoomList.value = res.data.map((item) => {
    return { label: item.storeName, value: item.id }
  })
}

const onChangeRadio = async (row) => {
  orderData.value = row
  if (row.jzfs === '自煎') {
    row.processMethod = { processMethodCost: 0 }
  } else {
    row.processMethod = orderData.value.processMethod
  }
  await onSaveMedicineList()
}
const generateProcess = (processMethod = {}) => {
  if (!processMethod.processMethodName) return ''
  return `${processMethod.processMethodName} ${processMethod.processMethodCmemo || ''}`
}
const generateExpress = (express = {}) => {
  if (!express.expressMode) return ''
  return `【${express.expressMode || ''}】${express.contactName || ''}，${express.contactPhone || ''}，${express.provinceName || ''}${express.cityName || ''}${
    express.countyName || ''
  }${express.addressDetail || ''} ${express.expressCmemo || ''}`
}
const onClickProcessOpen = (row, state) => {
  orderData.value = row
  if (row.jzfs === '代煎' && state === 1) {
    processOpen.value = true
  }
  if (state === 2) {
    expressOpen.value = true
  }
}
const onProcessOk = async (row) => {
  if (row.processMethodName) {
    orderData.value.processMethod = row
  } else {
    orderData.value.express = row
  }
  const findState = prescriptionList.value.findIndex((x) => x.drugStoreId === orderData.value.drugStoreId)
  if (findState !== -1) {
    prescriptionList.value.splice(findState, 1, orderData.value)
  }
  await onSaveMedicineList()
}

// const onBlurDepositPrice = async (select = {}) => {
//   select?.lsh && (deposit.value = select?.lsh)
//   const res = await post('/outp/mzdj/getDepositSlip', { lsh: deposit.value })
//   if (res.code !== 0) return message.error(res.msg)
//   depositPrice.value = res.data.dpJe
// }

const onDiscountsSuccess = async (params) => {
  const { code, msg } = await post('/outp/oupCharge/outpClinicalDiscount', { ...params, sfzsmx: packageSwitch.value ? 0 : 1 })
  if (code !== 0) return message.error(msg)
  discountsOneOpen.value = false
  message.success(msg)
  await chargeDetailList()
  getFeeCategoryList()
  getAmount()
}

const onSaveMedicineList = () => {
  prescriptionList.value.forEach(async (item) => {
    const params = {
      keycode: jzbh.value,
      ...item
    }
    const { code, msg } = await post('/outp/outpClinicalOrder/doSaveOutpTCMHead', params)
    if (code !== 0) return message.error(msg || '操作失败')
    getFeeCategoryList()
    getAmount()
  })
}

const onSuccessPrice = async (params = {}) => {
  const { code, msg, data } = await post(
    params.zffs === '2' ? '/outp/oupCharge/doPaymentForScan' : '/outp/oupCharge/doSaveOutPFee',
    {
      ...params,
      sflb: 'MZ',
      ids: tableDetailId.value,
      jzbh: jzbh.value,
      // yjdh: deposit.value,
      // patientCouponsId: couponId.value,
      // vipno: memberId.value, // 会员卡
      fbyh: params.fbwc,
      miFlag: 0,
      sfzsmx: packageSwitch.value ? 0 : 1
      // dyqzf: couponPrice.value, // 抵用券金额
      // dyqno: couponId.value // 抵用券id
    },
    {
      loading: true,
      timeout: 2 * 60 * 1000 // 超时时间2分钟
    }
  )
  if (code !== 0) return message.error(msg)
  message.success(msg)
  chargeOpen.value = false
  onPrint(data)
  // await onSaveMedicineList()
  // getFeeCategoryList()
  // chargeDetailList()
  onClickReset()
  couponRef.value?.getData()
}
const onPrint = async (item = {}) => {
  if (getSystemConfig('PRINT_INVOICE_AFTER_CHARGE') === '0') return
  const { code, msg, data } = await post('/outp/oupCharge/PrintMedicareCharges', { jzbh: jzbh.value, pjhm: item.pjhm, sftfbs: '0' })
  if (code !== 0) return message.error(msg)
  window.openExe?.rpt(data) //调用winform打印
}

const onClickReset = () => {
  formState.value = {
    stdate: dayjs().format('YYYY-MM-DD'),
    eddate: dayjs().format('YYYY-MM-DD'),
    kh: '',
    indInjuryNum: ''
  }
  jzbh.value = ''
  differenceAmount.value = 0
  prescriptionList.value = []
  depositPrice.value = 0
  deposit.value = ''
  tableData.value = {}
  tableDataType.value = []
  tableDataDetail.value = []
  tableDetailId.value = []
  packageSwitch.value = false
  cfbhData.value = []
  cfbhList.value = []
  czFlag.value = true
  cfFlag.value = true
}
const onClickRefresh = async () => {
  await chargeDetailList()
  getFeeCategoryList()
  getAmount()
}

// // 优惠券
// const onSuccessCoupon = async (id, price, state) => {
//   if (state === '优惠券') {
//     couponId.value = id
//     couponPrice.value = Number(price)
//   } else {
//     memberId.value = id
//     memberPrice.value = Number(price)
//   }
//   await getReceiptsAmount()
// }

// const getReceiptsAmount = async () => {
//   const { code, data, msg } = await post('/outp/oupCharge/getPennyDiscount', {
//     ysje: Number(medicalPrice.value), //应收金额
//     yhje: 0, //优惠金额
//     patientCouponsId: couponId.value, // 优惠券id
//     lsh: deposit.value, // 押金单号
//     offsetAmount: couponPrice.value // 抵用券金额
//   })
//   if (code !== 0) return message.error(msg)
//   differenceAmount.value = data.fbwc
//   categoryPrice.value = data.ssje
// }

const onSuccessPreferential = async () => {
  //自费
  const { code, msg } = await post(
    '/outp/oupCharge/doCheckClinicalOrdersIsSign',
    {
      ids: tableDetailId.value
    },
    {
      loading: true
    }
  )
  if (code !== 0) return message.error(msg)
  if (!Number(formatAmount(medicalPrice.value))) {
    formatZeroMoney()
  } else {
    chargeOpen.value = true
    // if (Number(formatAmount(categoryPrice.value)) > Number(formatAmount(depositPrice.value))) {
    //   chargeOpen.value = true
    // } else {
    //   message.error('押金金额大于实收金额')
    // }
  }
}
const formatZeroMoney = async () => {
  const { code, data } = await post('/outp/oupCharge/getChargeTypeList')
  if (code !== 0) return
  const chargeData = {}
  if (data && data.length > 0) {
    data.forEach((item) => {
      chargeData[item.zffsdm] = chargeData[item.zffsdm] ? chargeData[item.zffsdm] : 0
    })
  }
  chargeData.change = 0
  chargeData.fbyh = 0
  chargeData.yhje = 0
  chargeData.ysje = '0.00'
  chargeData.ssje = '0.00'
  onSuccessPrice(chargeData)
}
watch(
  () => jzbh.value,
  async () => {
    await getCfData()
    await chargeDetailList()
    getFeeCategoryList()
    getAmount()
    getDrugRooms()
  }
)

watch(
  () => deposit.value,
  () => {
    depositPrice.value = 0
  }
)
// // 计算减去押金
// watch(
//   () => depositPrice.value,
//   () => {
//     getReceiptsAmount()
//   }
// )
onMounted(() => {
  isCoupon.value = getSystemConfig('ENABLE_REGISTER_DISCOUNT') === '1' //启用挂号优惠功能
  isCharge.value = getSystemConfig('ENABLE_CHARGE_STANDARD_MODE') === '1' //收费标准
  isDeposit.value = getSystemConfig('CHARGE_DEPOSIT_ALLOW_AUTO_SELECT') === '1' //是否允许检索押金单
})
const onDelCost = async (item, xdFlag) => {
  const { code, msg } = await post('/outp/outpClinicalOrder/doDelTcmExtraCost', { cfdh: item.cfdh, xdFlag })
  if (code !== 0) return message.error(msg)
  message.success(msg)
  onClickRefresh()
}
</script>
<style lang="less" scoped>
:deep(.ant-radio-button-wrapper) {
  flex: 1;
  color: var(--primary-color);
  text-align: center;
  border-color: var(--primary-color);
  &::before {
    background-color: var(--primary-color);
  }
}
.order-footer {
  @apply cursor-pointer border-b py-1;
}
:deep(.ant-tabs-content-holder) {
  overflow: hidden;
}
.discount-input {
  :deep(.ant-input) {
    text-align: right;
  }
}
.color-placeholder {
  color: var(--disabled-text-color);
}
</style>
